export function queryParams(data, isPrefix = false) {
	let prefix = isPrefix ? '?' : ''
	    let _result = []
	
	    for (let key in data) {
	
	      let value = data[key]
	
	      // 去掉为空的参数
	
	      if (['', undefined, null].includes(value)) {
	
	        continue
	
	      }
	
	      if (value.constructor === Array) {
	
	        value.forEach(_value => {
	
	          _result.push(encodeURIComponent(key) + '[]=' + encodeURIComponent(_value))
	
	        })
	
	      } else {
	
	        _result.push(encodeURIComponent(key) + '=' + encodeURIComponent(value))
	
	      }
	
	    }
	    return _result.length ? prefix + _result.join('&') : ''
}


export function updateTitle(title) {
	uni.setNavigationBarTitle({
		title: title
	});
}

export function checkToUpdateAPP(isHome = false){
	//#ifdef APP-PLUS
	var _this=this;  
	plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
		var local_version = wgtinfo.versionCode
		console.log("local_version",local_version)
		const APPID = '6033754f23389f7dd3d324f9'
		// const TOKEN = '14fee8b3fb091163af02251b34eb004a'
		uni.request({
			url: `http://saasapi.ewguan.com/api/oa/GetAppVer`,
			method: 'GET',  
			data: {},  
			success: res => {
				console.log("res",res)
				let data = res.data
				console.log(data.data[0].Ver)
				if(data.data[0].Ver>local_version){   
					//安卓更新
					let platForm = uni.getSystemInfoSync().platform;
					if(platForm == 'android'){//安卓
						uni.showModal({
							content: "有新的版本发布，是否现在更新？",
							confirmText:"立即更新", 
							cancelText:"稍后再说",
							cancelColor: "#000000",
							success(e) {
								if(e.confirm){
									uni.showLoading({
										title:"更新中",
										mask:true
									})
									var dtask = plus.downloader.createDownload(data.data[0].DownUrl, {}, function ( d, status ) {
											// 下载完成  
											uni.hideLoading()
											if ( status == 200 ) {   
												plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){  
													uni.showToast({  
														title: '安装失败',  
														mask: false,  
														duration: 1500  
													});  
												})  
											} else {  
												 uni.showToast({  
													title: '更新失败',  
													mask: false,  
													duration: 1500  
												 });  
											}    
										});  
									dtask.start(); 
								}else if(e.cancel){
									console.log("用户点击了取消");
								}
							}
						})
					}else{
						let appleId= 1557596946 
						plus.runtime.launchApplication({
							action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
						}, function(e) {
							console.log('Open system default browser failed: ' + e.message);
						});
					}
				}else{
					if(!isHome){
						uni.showToast({
							title: '当前已是最新版本',  
							mask: false,  
							duration: 1500,  
							icon:"none"  
						});  
						return
					}
				}
			}
		})
	})
	//#endif
}